<template>
  <div
    id="systemset"
    v-loading="loading"
  >
    <v-tableTitle
      :btnConfig="btnConfig"
      :tableSelectData="tableSelectData"
      :title="$t('manage.reportconfig')"
      @newCreate="newCreate"
      @del="del"
    ></v-tableTitle>
    <v-table
      :pageSize="pageSize"
      :page="page"
      :tableConfig="tableConfig"
      :tableData="tableData"
      :total="total"
      @findData="getTableData"
      @getTableData="getTableData"
      @searhData="searhData"
      @selectData="selectData"
      @setdialog="setdialog"
      @upData="getTableData"
      ref="table"
    ></v-table>
  </div>
</template>

<script type="text/ecmascript-6">
import tableTitle from "commons/TableTitle";
import table from "commons/Table";
import baseMixin from "@/mixins/BaseMixin";
import config from "./Config";

export default {
  name: "reportSetting",
  mixins: [baseMixin, config],
  data () {
    return {
      loading: false,
      tableConfig: [
        {
          label: this.$t('manage.rptId'),
          prop: "rptId",
          input: "input",
        },
        {
          label: this.$t('manage.rptTitle'),
          prop: "rptTitle",
          input: "input",
        },
        {
          label: this.$t('config.locCategory'),
          prop: "categoryId",
          input: "select",
          options: this.getOptions("queryCategoryIdDropDown")
        },
        {
          label: this.$t('manage.customreporttype'),
          prop: "customreporttype",
          input: "select",
          options: this.getOptions("codelkup/REPORTTYPE")
        },
        {
          label: this.$t('manage.printoption'),
          prop: "printoption",
          input: "select",
          options: this.getOptions("codelkup/REPPRNOPT")
        },
        {
          label: this.$t('manage.defaultprinter'),
          prop: "defaultprinter",
          input: "select",
          options: this.getOptions("queryDefaultPrinterDropDown")
        },
        {
          label: this.$t('manage.canaccess'),
          prop: "canaccess",
          input: "select",
          options: this.getOptions("codelkup/RPTACCESS")
        },
        {
          label: this.$t('manage.baseReport'),
          prop: "baseReport",
          input: "select",
          options: [
            { code: '0', description: this.$t('code.no') },
            { code: '1', description: this.$t('code.yes') }
          ]
        },
        {
          label: this.$t('manage.rtx_bomkey'),
          prop: "comments",
          input: "input",
        },
      ],
      tableData: [],
      page: 1,
      pageSize: 10,
      total: 0,
      tableSelectData: [],
      tableSearhData: {},
    };
  },
  computed: {
    btnConfig () {
      return [
        { label: this.$t('common.create'), certigier: this.newStatus||!this.btnPermNameList.includes('WM040201'), invalid: "newCreate" },
        { label: this.$t('common.delete'), certigier: this.confirmStatus||!this.btnPermNameList.includes('WM040202'), disabled: true, invalid: "del" },
      ]
    }
  },
  created () {
  },
  methods: {
    //新建
    async newCreate () {
      this.$store.commit("setNewFlag", true);
      this.$router.push({ name: 'reportSettingDeawer' });
    },
    async del (data) {
      try {
        let res = await this.$api.post(`/deletePbsrptReports`, data);
        
          this.$message.success(res.returnMgr);
          let page = sessionStorage.getItem('page');
          this.getTableData(page, this.tableSearhData);
          
        
      } catch (e) {
        this.$message.error(e);
      }
    },
    //选中的内容
    selectData (data) {
      this.tableSelectData = data;
    },
    async getTableData (page, data) {
      try {
        this.loading = true;
        let res = await this.$api.post(`/queryPbsrptReports/${page}`, data);
        
          this.tableData = res.page.list;
          this.page = res.page.curpage;
          this.pageSize = res.page.pageSize;
          this.total = res.page.total;
        
      } catch (e) {
        this.$message.error(e);
      } finally {
        this.loading = false;
      }
    },
    //搜索的值
    searhData (data, up) {
      if (!up) {
        this.tableSearhData = data;
      } else {
        this.tableSearhData = data;
        this.getTableData(1, this.tableSearhData);
      }
    },
    //设置弹框
    setdialog (data) {
      this.$store.commit("setRouteData", data);
      this.$router.push({ name: 'reportSettingDeawer' });
    },
  },
  mounted () {
    
    this.$store.commit("setSkip", {});
    this.$store.commit("setNewFlag", false);
    this.$store.commit("setRouteData", {});
    this.getTableData(1, {});
  },
  watch: {
    tableSelectData (data) {
      if (this.permissionStatus) {
        if (data.length > 0) {
          this.deleteStatus = this.downStatus = false;
        } else {
          this.deleteStatus = this.downStatus = true;
        }
      }
    }
  },
  components: {
    "v-tableTitle": tableTitle,
    "v-table": table,
  }
};
</script>

<style scoped>
#systemset {
  width: 100%;
  height: 99%;
  padding-top: 6px;
}
</style>
